package com.java.multipledatasource.spring.item;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import javafx.print.Collation;
import net.sf.jsqlparser.expression.StringValue;
import org.apache.commons.collections.list.PredicatedList;

import java.io.*;
import java.lang.reflect.Method;
import java.util.*;

/**
 * @author hu
 * @version 1.0
 * @date 2020/12/24 0024 下午 12:09
 * @description
 */
public class Test {



    public static void main(String[] args) {
      List<Permission> permissionList = new ArrayList<>(10);

        String p1p = "sys:user:";
        Permission p1 = new Permission("sys:user", "人员管理", null);
        List<ChildItem> pc1 = new ArrayList<>(10);
        pc1.add(new ChildItem( p1p + "admin", "管理员") );
        pc1.add(new ChildItem( p1p + "admin", "阿姨管理") );
        pc1.add(new ChildItem( p1p + "admin", "师傅管理") );
        pc1.add(new ChildItem( p1p + "admin", "培训师管理") );
        pc1.add(new ChildItem( p1p + "admin", "培训师管理") );
        pc1.add(new ChildItem( p1p + "admin", "视频监控") );
        pc1.add(new ChildItem( p1p + "admin", "业务员管理") );
        p1.setChildren(pc1);
        permissionList.add(p1);

        String p2p = "sys:consumer:";
        Permission p2 = new Permission("sys:consumer", "用户管理", null);
        List<ChildItem> pc2 = new ArrayList<>(10);
        pc2.add(new ChildItem( p2p + "admin", "消费用户") );
        pc2.add(new ChildItem( p2p + "admin", "注册用户") );
        pc2.add(new ChildItem( p2p + "admin", "渠道管理") );
        pc2.add(new ChildItem( p2p + "admin", "业绩管理") );
        p2.setChildren(pc2);
        permissionList.add(p2);



        String p3p = "sys:order:";
        Permission p3 = new Permission("sys:order", "订单管理", null);
        List<ChildItem> pc3 = new ArrayList<>(10);
        pc3.add(new ChildItem( p3p + "admin", "所有订单") );
        pc3.add(new ChildItem( p3p + "admin", "未分类订单") );
        pc3.add(new ChildItem( p3p + "admin", "臻生活订单") );
        pc3.add(new ChildItem( p3p + "admin", "臻师傅订单") );
        pc3.add(new ChildItem( p3p + "admin", "积分商品订单") );
        pc3.add(new ChildItem( p3p + "admin", "内部耗材订单") );
        pc3.add(new ChildItem( p3p + "admin", "拼团订单") );
        pc3.add(new ChildItem( p3p + "admin", "积分订单") );
        pc3.add(new ChildItem( p3p + "admin", "订单详情") );
        p3.setChildren(pc3);
        permissionList.add(p3);

        String p4p = "sys:appo:";
        Permission p4 = new Permission("sys:appo", "预约管理", null);
        List<ChildItem> pc4 = new ArrayList<>(10);
        pc4.add(new ChildItem( p4p + "admin", "阿姨排单") );
        pc4.add(new ChildItem( p4p + "admin", "手动排单") );
        pc4.add(new ChildItem( p4p + "admin", "预约派单") );
        pc4.add(new ChildItem( p4p + "admin", "手动预约") );
        pc4.add(new ChildItem( p4p + "admin", "阿姨回访") );
        pc4.add(new ChildItem( p4p + "admin", "阿姨回访详情") );
        p4.setChildren(pc4);
        permissionList.add(p4);


        String p5p = "sys:servicemanage:";
        Permission p5 = new Permission("sys:servicemanage", "服务内容管理", null);
        List<ChildItem> pc5 = new ArrayList<>(10);
        pc5.add(new ChildItem( p5p + "admin", "试题管理") );
        pc5.add(new ChildItem( p5p + "admin", "服务素材") );
        pc5.add(new ChildItem( p5p + "admin", "阿姨打卡") );
        pc5.add(new ChildItem( p5p + "admin", "师傅打卡") );
        p5.setChildren(pc5);
        permissionList.add(p5);


        String p6p = "sys:marketing:";
        Permission p6 = new Permission("sys:marketing", "营销管理", null);
        List<ChildItem> pc6 = new ArrayList<>(10);
        pc6.add(new ChildItem( p6p + "admin", "产品管理") );
        pc6.add(new ChildItem( p6p + "admin", "优惠券管理") );
        pc6.add(new ChildItem( p6p + "admin", "服务步骤管理") );
        pc6.add(new ChildItem( p6p + "admin", "页面素材配置") );
        pc6.add(new ChildItem( p6p + "admin", "参数配置") );
        pc6.add(new ChildItem( p6p + "admin", "城市配置") );
        pc6.add(new ChildItem( p6p + "admin", "字典管理") );
        pc6.add(new ChildItem( p6p + "admin", "个人素材") );
        pc6.add(new ChildItem( p6p + "admin", "项目设置") );
        pc6.add(new ChildItem( p6p + "admin", "问题设置") );
        pc6.add(new ChildItem( p6p + "admin", "服务流程设置") );
        pc6.add(new ChildItem( p6p + "admin", "组合编辑") );
        pc6.add(new ChildItem( p6p + "admin", "预约选项设置") );
        pc6.add(new ChildItem( p6p + "admin", "开放城市设置") );
        pc6.add(new ChildItem( p6p + "admin", "素材管理") );
        pc6.add(new ChildItem( p6p + "admin", "城市参数") );
        p6.setChildren(pc6);
        permissionList.add(p6);


        String p7p = "sys:content:";
        Permission p7 = new Permission("sys:content", "内容管理", null);
        List<ChildItem> pc7 = new ArrayList<>(10);
        pc7.add(new ChildItem( p7p + "admin", "耗材管理") );
        p7.setChildren(pc7);
        permissionList.add(p7);


        String p8p = "sys:training:";
        Permission p8 = new Permission("sys:training", "培训管理", null);
        List<ChildItem> pc8 = new ArrayList<>(10);
        pc8.add(new ChildItem( p8p + "admin", "课程管理") );
        pc8.add(new ChildItem( p8p + "admin", "考试管理") );
        p8.setChildren(pc8);
        permissionList.add(p8);

        String p9p = "sys:report:";
        Permission p9 = new Permission("sys:report", "报表管理", null);
        List<ChildItem> pc9 = new ArrayList<>(10);
        pc9.add(new ChildItem( p9p + "admin", "用户分布报表") );
        pc9.add(new ChildItem( p9p + "admin", "营业额报表") );
        pc9.add(new ChildItem( p9p + "admin", "产品订单报表") );
        pc9.add(new ChildItem( p9p + "admin", "预约单报表") );
        p9.setChildren(pc9);
        permissionList.add(p9);
        String s = JSON.toJSONString(permissionList);
      //  JSONObject jsonObject = JSON.parseObject(s);
        System.out.println(s);
        //  createJsonFile(JSON.parseObject(s), "F:\\HY\\777\\1.json");
    }
    private  static void createJsonFile(Object jsonData, String filePath) {
        String content = JSON.toJSONString(jsonData, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat);
        // 标记文件生成是否成功
        boolean flag = true;
        // 生成json格式文件
        try {
            // 保证创建一个新文件
            File file = new File(filePath);
            if (!file.getParentFile().exists()) { // 如果父目录不存在，创建父目录
                file.getParentFile().mkdirs();
            }
            if (file.exists()) { // 如果已存在,删除旧文件
                file.delete();
            }
            file.createNewFile();
            // 将格式化后的字符串写入文件
            Writer write = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
            write.write(content);
            write.flush();
            write.close();
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }
    }
}
